PHP Array 简单操作小结

Categories: PHP; Tagged with: ; @ August 28th, 2010 11:32

1. 创建Array: $arraySites = array();

2. addItem: $arraySites[$site->id] = $site;

3. 使用foreach遍历Array:

foreach ($arraySites as $site) { // 遍历每一个Site.
	// do something.
}

// Or:
foreach($array as $key=>$value)
{
echo "$key,$value ";
}

4. length: count($arraySite);

5.  打散/切割 Array : array_chunk($mails, $MAX_MAILS_PER_SMTP_SESSION, true);

该方法将会根据设定的大小对原数组进行切割, 生成多个小的数组(最后一个可能会少于单元大小), 第三个参数控制是否在打散后的数组内保留其原有key.

复制/移除 数组: http://liguoliang.com/2010/copy-and-remove-array-to-array-in-php/

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.